//
//  Pac_TipsSureBtn.m
//  TY-C
//
//  Created by 张雅 on 2024/3/17.
//

#import "Pac_TipsSureBtn.h"
#import "ComonFile.h"

@implementation Pac_TipsSureBtn



- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ZYQWIDTH, [UIApplication sharedApplication].keyWindow.frame.size.height);
        
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 10 * IPADSCALE;
        [self initViews];
        [self initFrames];
        self.backgroundColor = RGBAColor(0, 0, 0, 0.2);
    }
    return self;
}
- (void)initFrames {
    
    [_whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(225 * IPADSCALE));
        make.height.equalTo(@(160* IPADSCALE));
        make.center.equalTo(self);
    }];
    _whiteView.backgroundColor = RGBColor(255, 255, 255);

    [_topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(_whiteView);
        make.height.equalTo(@(27*IPADSCALE));
    }];
    _topLab.text = @"  提示";
    _topLab.font = ZYQFONT(18);
    _topLab.textColor = RGBColor(102, 102, 102);
    _topLab.backgroundColor = RGBColor(250, 250, 250);
    
    [_iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@(22 * IPADSCALE));
        make.top.equalTo(_topLab.mas_bottom).offset(18*IPADSCALE);
        make.centerX.equalTo(_whiteView.mas_centerX);
    }];
    _iconImg.image = [UIImage imageNamed:@"logon_!"];
    
    [_bigTipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(_iconImg.mas_bottom).offset(5*IPADSCALE);
        make.height.equalTo(@(13.5 * IPADSCALE));
    }];
    _bigTipsLab.textColor = RGBColor(238, 138, 82);
    _bigTipsLab.textAlignment = NSTextAlignmentCenter;
    _bigTipsLab.font = ZYQFONT(18);
    _bigTipsLab.text = @"蓝牙连接断开";
    
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(_bigTipsLab.mas_bottom).offset(5*IPADSCALE);
        make.height.equalTo(@(12 * IPADSCALE));
    }];
    _titleLab.textColor = RGBColor(102, 102, 102);
    _titleLab.textAlignment = NSTextAlignmentCenter;
    _titleLab.font = ZYQFONT(16);
    _titleLab.text = @"请确定蓝牙已打开，且在通信范围内";
    
    [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(80 * IPADSCALE));
        make.height.equalTo(@(30 * IPADSCALE));
        make.bottom.equalTo(_whiteView.mas_bottom).offset(-15 *IPADSCALE);
        make.centerX.equalTo(_whiteView.mas_centerX);
    }];
    _sureBtn.clipsToBounds = YES;
    _sureBtn.layer.cornerRadius = 15 *IPADSCALE;
    [_sureBtn setBackgroundColor:RGBColor(13, 157, 219)];
    [_sureBtn setTitle:@"确认" forState:0];
    [_sureBtn setTitleColor:[UIColor whiteColor] forState:0];
    _sureBtn.titleLabel.font = ZYQFONT(20);
    [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)sureBtnAction {
    if (_sureActionMiddleDone) {
        _sureActionMiddleDone(self,0,@"");
        [self hidden];
        [self removeFromSuperview];

    }
}

- (void)hidden {
    if (self) {
        [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, 0, 0, 0);
            self.hidden = YES;
        } completion:^(BOOL finished) {
            
        }];
        return;
        
        
        [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, 0, ZYQWIDTH, [UIApplication sharedApplication].keyWindow.frame.size.height);
            self.hidden = NO;
        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)sureBtnwithDoneBlock:(Pac_TipsSureBtn_SureAction)doneBlock CancelBlock:(Pac_TipsSureBtn_CancleAction)cancelBlockOrNil {
    _sureActionMiddleDone = doneBlock;
    _cancleActionMiddleDone = cancelBlockOrNil;
}

- (void)initViews {
    _whiteView = [UIView new];
    _topLab = [UILabel new];
    _iconImg = [UIImageView new];
    _bigTipsLab = [UILabel new];
    _titleLab = [UILabel new];
    _sureBtn = [UIButton new];
    
    [self addSubview:_whiteView];

    [_whiteView addSubview:_topLab];
    [_whiteView addSubview:_iconImg];
    [_whiteView addSubview:_bigTipsLab];
    [_whiteView addSubview:_titleLab];
    [_whiteView addSubview:_sureBtn];

}

@end
